import React from 'react'
// ===================================================================== Temp
import TableModal from '#cpt/temp/TableModal'
// ===================================================================== Declare
const { $fn, $Lazy } = window
// ===================================================================== Lazy
const $cache = $Lazy.file(()=>import('#private/cache-api'))
// ===================================================================== component
class Index extends React.Component{
	state = {
		data:[],
		pag: {},
		selectedKeys:[],
		selectedRows: [],
		forms : [
			{ label: '设备名称',		name: 'device_name',	type: 'select', idStr:'device_name', nameStr:'device_name', width:200 },
			{ label: '结果时间',		names: ['start_at','end_at'], type:'date-range' },
		]
	}
	
	model = {}
	
	// 获取表单选择数据
	getSeelct = () => {
		const { forms } = this.state
		$fn.setModalRows(forms, [ 'device_name' ], ()=>{
			$cache.then( async f => {
				// 设备名称
				$fn.setRow(forms, 'device_name',  await f.getCache({ api:'device_result' } ))
				//
				this.setState({ forms })
			})
		})
	}
	
	open = (rows, record) => {
		this.modal.open()
		const { spec_code, kind_id } = rows
		const { result_suggestion_content, uuid, spec_abnormal, content, result, spec_type  } = record || {}
		// 搜索参数
		this.query = { spec_code, kind_id }
		// 提交参数
		const submit = { result_suggestion_content, uuid, spec_abnormal, content, result, spec_type }
		this.submit = { forms: JSON.stringify([ submit ])  }
		// 获取下拉
		this.getSeelct()
		//
		this.fetch()
	}
	// paging
	fetch = () => $fn.fetch.call(this, 'result-unit-item/getDeviceResultList', { isIndex:true })
	
	// 表单
	cols = [
		{ title: '实验号', 		dataIndex: 'lab_tag', 				width:100 },
		{ title: '结果时间', 	dataIndex: 'msg_send_at', 			...$fn.table.time },
		{ title: '设备编号', 	dataIndex: 'device_uid', 			width:80 },
		{ title: '设备名称', 	dataIndex: 'device_name', 			width:200 },
		{ title: '项目', 		dataIndex: 'kind_name', 			width:200 },
		{ title: '值', 			dataIndex: 'value', 				...$fn.table.num  },
		{ title: '值1', 		dataIndex: 'value1', 				...$fn.table.num  },
	]
	
	render(){
		return TableModal.call(this,{ title:'设置结果', width:'99%', height:'80%', api:'result-unit-item/updateall', table:{ width:1200 }})
	}
}

export default Index